//index.js
//获取应用实例
const app = getApp()
const config = require('../../config.js');
Page({
	data: {
		motto: 'Hello World',
		userInfo: {},
		hasUserInfo: false,
		canIUse: wx.canIUse('button.open-type.getUserInfo'),
		dataList: [{
				bannerUrl: '../../static/img/baner.png'
			},
			{
				bannerUrl: '../../static/img/bg_top.png'
			},
			{
				bannerUrl: '../../static/img/baner.png'
			}
		],
		navList: [],
		companyInfo: {}, // 公司简介
		noData: false,
		markers: [{
			iconPath: "../../static/img/icon_dt.png",
			id: 0,
			latitude: 23.099994,
			longitude: 113.324520,
			width: 20,
			height: 20
		}],
	},

	regionchange(e) {
		console.log(e.type)
	},
	markertap(e) {
		console.log(e.detail.markerId)
	},
	controltap(e) {
		console.log(e.detail.controlId)
	},
	//事件处理函数
	bindViewTap: function() {
		wx.navigateTo({
			url: '../logs/logs'
		})
	},
	onShow() {
		this.getAll()
		this.banner()
		this.companyInfo()
	},
// 获取首页服务内容
	getAll() {
		let vm = this
		wx.request({
			url: config.getAll,
			data: {},
			header: {
				// tenantId: 1003,
				'content-type': 'application/json', // 默认值
			},
			success(response) {
				console.log(response.data)
				let result = response.data
				if (result.code === '0000') {
					if (result.data) {
						vm.setData({
							navList: result.data,
							noData: false
						})
					} else {
						vm.setData({
							noData: true
						})
					}

				} else {
					vm.setData({
						noData: true
					})
				}
			}
		})
	},
	// 获取首页服务内容
	findRecomend() {
		let vm = this
		wx.request({
			url: config.findRecomend,
			data: {},
			header: {
				tenantId: 1003,
				'content-type': 'application/json', // 默认值
			},
			success(response) {
				console.log(response.data)
				let result = response.data
				if (result.code === '0000') {
					if (result.data) {
						vm.setData({
							navList: result.data,
							noData: false
						})
					} else {
						vm.setData({
							noData: true
						})
					}

				} else {
					vm.setData({
						noData: true
					})
				}
			}
		})
	},
	// 获取banner
	banner() {
		let vm = this
		wx.request({
			url: config.findAll,
			data: {
				appType: 1
			},
			header: {
				tenantId: 1003,
				'content-type': 'application/json', // 默认值
			},
			success(response) {
				console.log(response.data)
				let result = response.data
				if (result.code === '0000') {
					if (result.data) {
						vm.setData({
							dataList: result.data,
						})
					}
				}
			}
		})
	},
	// 获取公司简介
	companyInfo() {
		let vm = this
		wx.request({
			url: config.companyInfo,
			data: {},
			header: {
				tenantId: 1003,
				'content-type': 'application/json', // 默认值
			},
			success(response) {
				console.log(response.data)
				let result = response.data
				if (result.code === '0000') {
					if (result.data) {
						vm.setData({
							companyInfo: result.data,
						})
					}
				}
			}
		})
	},
	getUserInfo: function(e) {
		console.log(e)
		app.globalData.userInfo = e.detail.userInfo
		this.setData({
			userInfo: e.detail.userInfo,
			hasUserInfo: true
		})
	},
	// 拨打电话
	telPhone(e) {
		let phone = e.currentTarget.dataset.phone
		wx.makePhoneCall({
			phoneNumber: phone
		})
	},
	// 去服务页 搜索
	getService() {
		// app.globalData.type = 'auto'
		wx.navigateTo({
			url: '/pages/searchList/searchList',
		})
	},
	getList(e) {
		let id = e.currentTarget.dataset.id
		wx.navigateTo({
			url: '/pages/serviceList/serviceList?id=' + id,
		})
	}
})
